package com.shiliao.app.activity.index.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.yimei.framework.base.ui.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yinzhiqiang on 2017/9/11.
 */

public class FragmentAdapter extends FragmentStatePagerAdapter {
    private List<BaseFragment> fragments = null;
    private List<BaseFragment> fragmentList;

    public FragmentAdapter(FragmentManager fm, List<BaseFragment> fragmentList) {
        super(fm);
        fragments = new ArrayList<BaseFragment>();
        this.fragmentList = fragmentList;
    }

    public void setList(List<BaseFragment> fragmentList) {
        if (fragmentList != null) {
            this.fragments.addAll(fragmentList);
            notifyDataSetChanged();
        }

    }

    public void clear() {
        if (fragments != null) {
            fragments.clear();
            notifyDataSetChanged();
        }

    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

}
